package com.xlh.adapter;

import java.util.List;

import com.xlh.Utils.Constant;
import com.xlh.bean.CharBean;
import com.xlh.outside.R;

import android.content.Context;
import android.graphics.Color;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ChatAdapter extends BaseAdapter {

	private List<CharBean> data;
	private LayoutInflater mInflater;

	public ChatAdapter(Context context , List<CharBean> data) {
		// TODO Auto-generated constructor stub
		this.data = data;
		mInflater = LayoutInflater.from(context);

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data == null? 0 : data.size();
	}

	@Override
	public CharBean getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView == null) {
			convertView = mInflater.inflate(R.layout.char_item,parent,false);
		}
		TextView tv1 = (TextView) convertView.findViewById(R.id.chat_title);
		TextView tv2 = (TextView) convertView.findViewById(R.id.chat_content);

		CharBean charBean = data.get(position);
		//tv1.setText(charBean.getmTitle());
		tv2.setTextColor(Color.parseColor(Constant.getAppColor().getFontColor() ));
		tv2.setText(charBean.getmContent());
		tv2.setClickable(true);
		tv2.setMovementMethod(LinkMovementMethod.getInstance());
		//String a01 = charBean.getAction01();
		//String a02 = charBean.getAction02();
		/*
		if(a01 != null ) {
			Log.e("XXX", "玩家ID：" + a01);
		}

		if(a02 != null) {
			Log.e("XXX", "玩家物件ID：" + a02);
		}*/


		return convertView;
	}

	public void setData(List<CharBean> mChatBean) {
		// TODO Auto-generated method stub
		if(mChatBean != null) {
			this.data = mChatBean;
		}
		this.notifyDataSetChanged();
	}

}
